package com.ccc.qrcode.controller;

import com.ccc.qrcode.util.QRCodeUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * 测试接口
 *
 * @author superC
 * @version 1.0.0
 * @date 2023-07-27
 */

@RestController
@RequestMapping("/test")
public class QrcodeTestController {

    protected static final Logger logger = LoggerFactory.getLogger(QrcodeTestController.class);

    @Resource
    protected HttpServletResponse response;

    /**
     * 生成链接或二维码
     */
    @GetMapping("/getQRcode")
    public void getQRcode(@RequestParam String id) {
        try {
            String text = "https://www.baidu.com";
            QRCodeUtils.encode(text, response.getOutputStream());
        } catch (Exception e) {
            logger.error("【捕获异常-生成链接或二维码】\r\n异常记录：", e);
        }
    }

    /**
     * 获取人员二维码
     */
    @GetMapping("/getQRcode2")
    public void getQRcode2(@RequestParam String id) {
        try {
            QRCodeUtils.encode(id, response.getOutputStream());
        } catch (Exception e) {
            logger.error("【捕获异常-生成链接或二维码】\r\n异常记录：", e);
        }
    }

}
